﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;
using OpenQA.Selenium;

namespace AutoSubmit.Lib.Ebusinessarticles
{
    public class Ebusinessarticles : ActionPage
    {
        public override String vGetArticleURL()
        {
            if (m_status != SubmitStatus.SUCCESS)
            {
                return "";
            }

            if (m_article.m_url.Length > 0)
            {
                m_driver.Navigate().GoToUrl(m_article.m_url);
            }

            // find new article
            ReadOnlyCollection<IWebElement> hrefs = WebDriverExtension.FindElements(m_driver, By.XPath(m_article.m_articlesListXPath), 5);
            foreach (IWebElement ele in hrefs)
            {
                if (ele.Text.Contains(m_article.m_title))
                    return ele.FindElement(By.XPath("./td[2]/a")).GetAttribute("href");
            }

            return "";
        }
    }
}
